package com.scuec.demo.controller;

import com.github.pagehelper.PageInfo;
import com.scuec.demo.entity.StudentInfo;
import com.scuec.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/stu")
@CrossOrigin
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping("/pages")
    public PageInfo<StudentInfo> getPageStudent(Integer pageNum, Integer pageSize){
        PageInfo<StudentInfo> pageInfo = studentService.getStudentPages(pageNum,pageSize);
        return pageInfo;
    }
    // http://localhost:8080/stu/abc   get  参数
    @GetMapping("/abc")
    public String getStudent() {
        System.out.println("getStudent");
        return "student20250517";
    }
    //http://localhost:8080/stu/list
    @GetMapping("/list")
    public List<StudentInfo> getStudentList() {
        List<StudentInfo> studentInfo = studentService.getStudentInfo();
        return studentInfo;
    }



    // http://localhost:8080/stu/find?id=222
    @GetMapping("/find")
    public StudentInfo getStudentById(Integer id) {
        StudentInfo studentInfo = studentService.getStudentInfoById(id);
        return studentInfo;
    }

    // http://localhost:8080/stu/delete?id=222
    @GetMapping("/delete")
    public int deleteStudentById(Integer id) {
        int result = studentService.deleteStudentInfoById(id);
        return result;
    }

    // http://localhost:8080/stu/insert
    @PostMapping("/insert")
    public int insertStudentInfo(@RequestBody StudentInfo studentInfo) {
        int result = studentService.insertStudentInfo(studentInfo);
        return result;
    }

    @PutMapping("/update")
    public int updateStudentInfo(@RequestBody StudentInfo studentInfo) {
        int result = studentService.updateStudentInfo(studentInfo);
        return result;
    }
    @GetMapping("list")
    public  String getAllStudent(){
        return "";
    }
}
